﻿using Reflexive.IO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Reflexive.IO.Examples
{

    public class ByteConverter : TypeConverter, ITypeConverter<string,byte[]>
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return true;
        }

        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            string ev = (string)value;
            return System.Text.ASCIIEncoding.UTF8.GetBytes(ev);
        }


        public byte[] Convert(string source)
        {
            return (byte[])ConvertTo(source, typeof(byte[]));
        }
    }
}
